layui.use(['upload','form','layer'],function () {
    var upload = layui.upload;
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.$;
    //执行实例
    var flag = false;
    var uploadInst = upload.render({
        elem: '#test1' //绑定元素
        ,url: serverUrl + '/appinfos' //上传接口
        ,auto: false
        ,bindAction: '#btnAdd'
        ,field: 'myfile'
        // ,data:{appName:$("[name=apkName]").val()}
        ,before: function (obj) {
            flag = true;
            this.data = {apkName:$("[name=apkName]").val()}
        }
        ,done: function(res){
            //上传完毕回调
            console.log(res);
        }
        ,error: function(){
            //请求异常回调
        }

    });

    $("#btnAdd").click(function () {
        //如果选择了文件，再点添加就不执行下面的代码
        if(!flag) {
            var formData = new FormData();
            formData.append("apkName", $("[name=apkName]").val());
            $.ajax({
                url: serverUrl + "/appinfos",
                data: formData,
                processData : false, // 使数据不做处理
                contentType : false, // 不要设置Content-Type请求头
                type: 'post',
                dataType: 'json',
                success: function (r) {
                    alert(r.msg);
                }
            })
        }
    })
});